package com.changgou.order.consumer;

import com.alibaba.fastjson.JSON;
import com.changgou.order.vo.CartItemDto;
import entity.TypeEnum;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @author ljh
 * @version 1.0
 * @date 2021/1/18 17:14
 * @description 标题
 * @package com.changgou.order.consumer
 */
@Component
@RabbitListener(queues = "queue.cart")
public class Cartlistener {
    //接收消息实现购物车数据的CRUD
    @RabbitHandler
    public void jieshouMsg(String msg) {
        //获取数据
        CartItemDto cartItemDto = JSON.parseObject(msg, CartItemDto.class);
        //判断操作类型
        TypeEnum typeEnum = TypeEnum.getTypeEnum(cartItemDto.getType());
        if (typeEnum != null) {
            switch (typeEnum) {
                case ADD:
                    //添加商品到购物车

                    break;
                case DELETE:
                    //删除购物车上牌
                    break;
                case UPDATE:
                    //更新购物车数量
                    break;
                default:
                    //其他操作类型
                    break;
            }
        } else {
            System.out.println("有问题");
        }
    }
}
